let id = null;
function doIt(speed) {
  function writeCode(pre, code, fn) {
    let codeWrapper = document.querySelector("#code");
    let style = document.querySelector("#styleTag");
    let n = 0;
    id = setInterval(() => {
      n += speed;
      codeWrapper.innerHTML = code.substring(0, n);
      style.innerHTML = code.substring(0, n);
      codeWrapper.scrollTop = codeWrapper.scrollHeight;
      if (n >= code.length) {
        window.clearInterval(id);
        fn && fn();
      }
    }, 1);
  }
  let code = `
  #triangle-right{
    position: absolute;
    z-index: 999;
    top: 244px;
    left: 240px;
  }
  
  #triangle-left{
    position: absolute;
    z-index: 999;
    top: 244px;
    left: 110px;
    transform: scaleX(-1);
  }
  
  .triangle1 {
    width: 0;
    height: 0;
    border-left: 3px solid transparent;
    border-right: 3px solid transparent;
    border-top: 5px solid #010101;
    position: absolute;
    z-index: 999;
  }
  
  .triangle2 {
    width: 0;
    height: 0;
    left: 12px;
    top: 10px;
    border-left: 3px solid transparent;
    border-right: 3px solid transparent;
    border-top: 5px solid #010101;
    position: absolute;
    z-index: 999;
  }
  .triangle3 {
    width: 0;
    height: 0;
    left: 8px;
    top: 22px;
    border-left: 3px solid transparent;
    border-right: 3px solid transparent;
    border-top: 5px solid #010101;
    position: absolute;
    z-index: 999;
  }
  
  .eye.left {
    position: absolute;
    top: 38px;
    left: 62px;
    width: 110px;
    height: 196px;
    background: #fba919;
    border-radius: 65% 35% 0% 55%/50% 15% 50% 50%;
    border: 3px solid #010101;
    overflow: hidden;
    z-index: 1;
  }
  
    .eye.left::after{
    display: block;
    position: relative;
    width: 150px;
    height: 210px;
    content: "";
    top: -50px;
    left: 5px;
    border:solid 3px #010101;
    border-color:#000 transparent transparent transparent;
    border-radius: 100px 100px 0% 0%/5%;
    transform: rotate(185deg);
  }
  
    .eye.left::before{
    content: "";
    position: absolute;
    top: 163px;
    width: 150px;
    height: 210px;
    border-radius: 100px 100px 0% 0%/0%;
    transform: rotate(5deg);
    background: #fff;
  }
  
    .eyeball1{
    background-color: #010101;
    display: block;
    left: 83px;
    content: "";
    position: absolute;
    top: 166px;
    width: 24px;
    height: 10px;
    border-radius: 0% 0% 50% 50%/0 0 100% 100%;
  }
  
    .eyeball2{
    background-color: #010101;
    display: block;
    left: 3px;
    position: absolute;
    top: 166px;
    width: 24px;
    height: 10px;
    border-radius: 0% 0% 50% 50%/0 0 100% 100%;
    z-index: 1;
  }
  
  .eye.right::after{
    display: block;
    position: relative;
    width: 150px;
    height: 210px;
    content: "";
    top: -50px;
    left:-25px;
    border:solid 3px #010101;
    border-color:#000 transparent transparent transparent;
    border-radius: 100px 100px 0% 0%/5%;
    transform: rotate(-185deg);
  }
  
    .eye.right::before{
    content: "";
    position: absolute;
    top: 162px;
    width: 150px;
    height: 210px;
    border-radius: 100px 100px 0% 0%/0%;
    transform: rotate(-4deg);
    background: #fff;
  }
  
  .eye.right {
    position: absolute;
    left: 175px;
    top: 38px;
    width: 110px;
    height: 196px;
    border-radius: 35% 65% 55% 0%/15% 50% 50% 50%;
    background: #fba919;
    border: 3px solid #010101;
    overflow: hidden;
    z-index: 1;
  }
  
  .nose {
    position: absolute;
    top: 225px;
    left: 150px;
    width: 45px;
    height: 25px;
    background: #fbbfcb;
    border-radius: 100%;
    border: 3px solid #000200;
    z-index: 1;
  }
  
  .snout1 {
    width:80px;
    height:50px;
    background-color:#fffd78;
    border:3px solid #010101;
    position:absolute;
    top:220px;
    left:80px;
    border-right-color:transparent;
    border-radius:50%;
    transform: rotate(-25deg);
    border-top-left-radius: 100% 100%;
    border-top-right-radius: 100% 40%;
    border-bottom-left-radius: 100% 100%;
    border-bottom-right-radius: 12% 100%;
  }
  
    .snout1small {
    width:60px;
    height:15px;
    background-color:#fffd78;
    position:absolute;
    top:255px;
    left:122px;
    border-radius:50%;
    transform: rotate(140deg) scaleX(-1);
    border-top-left-radius: 50% 100%;
    border-top-right-radius: 0% 50%;
    border-bottom-left-radius: 50% 100%;
    border-bottom-right-radius: 0% 100%;
    border-left: 3px solid #010101;
    border-right-color:transparent;
    border-top-color:transparent;
    border-bottom-color:transparent;
    overflow: hidden;
  }
  
  .snout2 {
    width:80px;
    height:50px;
    background-color:#fffd78;
    position:absolute;
    top:220px;
    left:185px;
    border-radius:50%;
    transform: rotate(205deg);
    border-top-left-radius: 100% 100%;
    border-top-right-radius: 0% 100%;
    border-bottom-left-radius: 100% 100%;
    border-bottom-right-radius: 0% 100%;
    border: 3px solid #010101;
    border-right-color:transparent;
  }
  
    .snout2small {
    width:60px;
    height:15px;
    background-color:#fffd78;
    position:absolute;
    top:255px;
    left:165px;
    border-radius:50%;
    transform: rotate(220deg);
    border-top-left-radius: 50% 100%;
    border-top-right-radius: 0% 50%;
    border-bottom-left-radius: 50% 100%;
    border-bottom-right-radius: 0% 100%;
    border-left: 3px solid #010101;
    border-right-color:transparent;
    border-top-color:transparent;
    border-bottom-color:transparent;
    overflow: hidden;
  }
  
  .whisker8 {
    transform: scaleX(-1) scale(0.7) rotate(30deg);
    top: -145px;
    left: 435px;
    position: absolute;
    z-index: 999;
    -moz-transform: scaleX(-1);
    -o-transform: scaleX(-1);
    -webkit-transform: scaleX(-1) scale(0.7) rotate(30deg);
    filter: FlipH;
    -ms-filter: “FlipH”;
  }
  
  .whisker7 {
    transform: scaleX(-1) rotate(5deg);
    top: -85px;
    left: 640px;
    position: absolute;
    z-index: 999;
  }
  
  .whisker6 {
    transform: scaleX(-1) rotate(-15deg);
    top: 100px;
    left: 700px;
    position: absolute;
    z-index: 999;
  }
  
  .whisker5 {
    transform: scaleX(-1) rotate(-45deg);
    top: 375px;
    left: 675px;
    position: absolute;
    z-index: 999;
  }
  
  .whisker4 {
    transform: rotate(30deg) scale(0.7);
    top: -145px;
    left: -85px;
    position: absolute;
    z-index: 999;
  }
  
  .whisker3 {
    transform: rotate(5deg);
    top: -85px;
    left: -290px;
    position: absolute;
    z-index: 999;
  }
  
  .whisker2 {
    transform: rotate(-15deg);
    top: 100px;
    left: -350px;
    position: absolute;
    z-index: 999;
  }
  
  .whisker1 {
    transform: rotate(-45deg);
    top: 375px;
    left: -325px;
    position: absolute;
    z-index: 999;
  }
  
  .stripes1 {
    position: absolute;
  }
  .stripe1 {
    width: 12px;
    height: 40px;
    border-top: 10px solid #010101;
    background: #010101;
    border-radius: 60px 0% 100% 100%/200px 0% 100% 100%;
    position: absolute;
    left: 319px;
    top: 180px;
    overflow: hidden;
  }
  .stripeA{
    background-color: #010101;
    display: block;
    left: 320px;
    position: absolute;
    top: 225px;
    width: 11px;
    height: 10px;
    border-radius: 0 0 50% 50%/0 0 100% 100%;
    transform: rotate(355deg);
  }
  
  .stripes2{
    transform: scale(0.8);
    position: absolute;
    left: 78px;
    top: 42px;
  }
  
  .stripe2{
    width:12px;
    height: 40px;
    border-top: 10px solid #010101;
    background: #010101;
    border-radius: 60px 0% 100% 100%/200px 0% 100% 100%;
    position: absolute;
    left: 319px;
    top: 180px;
    overflow: hidden;
  }
  .stripeB{
    background-color: #010101;
    display: block;
    left: 320px;
    position: absolute;
    top: 225px;
    width: 11px;
    height: 10px;
    border-radius: 0 0 50% 50%/0 0 100% 100%;
    transform: rotate(355deg);
  }
  
  .stripes3{
    transform: scale(0.6);
    position: absolute;
    left: 154px;
    top: 84px;
  }
  
  .stripe3{
    width:12px;
    height: 40px;
    border-top: 10px solid #010101;
    background: #010101;
    border-radius: 60px 0% 100% 100%/200px 0% 100% 100%;
    position: absolute;
    left: 319px;
    top: 180px;
    overflow: hidden;
  }
  
  .stripeC{
    background-color: #010101;
    display: block;
    left: 320px;
    position: absolute;
    top: 225px;
    width: 11px;
    height: 10px;
    border-radius: 0 0 50% 50%/0 0 100% 100%;
    transform: rotate(355deg);
  }
  
  .stripes4{
    transform: scale(0.3);
    position: absolute;
    left: 260px;
    top: 148px;
  }
  
  .stripe4{
    width:12px;
    height: 40px;
    border-top: 10px solid #010101;
    background: #010101;
    border-radius: 60px 0% 100% 100%/200px 0% 100% 100%;
    position: absolute;
    left: 319px;
    top: 180px;
    overflow: hidden;
  }
  
  .stripeD{
    background-color: #010101;
    display: block;
    left: 320px;
    position: absolute;
    top: 225px;
    width: 11px;
    height: 10px;
    border-radius: 0 0 50% 50%/0 0 100% 100%;
    transform: rotate(355deg);
  }
  
  .whisker.right{
    transform: rotate(-1deg);
    background:#010101;
    width: 30px;
    height: 3px;
    position: absolute;
    left: 20px;
    border-top-right-radius: 50% 100%;
    border-top-left-radius: 50% 100%;
    border-bottom-left-radius: 50% 100%;
    border-bottom-right-radius: 50% 100%;
  }
  
  .whisker.left{
    transform: rotate(-1deg);
    background:#010101;
    width: 30px;
    height: 3px;
    position: absolute;
    left: 20px;
    border-top-right-radius: 50% 100%;
    border-top-left-radius: 50% 100%;
    border-bottom-left-radius: 50% 100%;
    border-bottom-right-radius: 50% 100%;
  }

  .face {
    transform: rotate(36000deg);
  }
  `;
  writeCode("", code);
}
doIt(2);
let up = document.querySelector("#speedUp");
let down = document.querySelector("#speedDown");
let reset = document.querySelector("#reset");
up.addEventListener("click", () => {
  window.clearInterval(id);
  doIt(5);
});
down.addEventListener("click", () => {
  window.clearInterval(id);
  doIt(1);
});
reset.addEventListener("click", () => {
  window.clearInterval(id);
  doIt(2);
});
